<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="keys" content="">
    <meta name="author" content="">
	<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="../css/font-awesome.min.css">
	<link rel="stylesheet" href="../css/login.css">
	<style>

	</style>
  </head>
  <body>
    <nav class="navbar navbar-inner navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <div><a class="navbar-brand" href="index.html" style="font-size:32px;">众筹网-创意产品众筹平台</a></div>
        </div>
      </div>
    </nav>

    <div class="container"> 
      <form class="form-signin"  id="userForm" role="form"  method="post">
        <h2 class="form-signin-heading"><i class="glyphicon glyphicon-log-in"></i> 用户登录</h2>
		  <div class="form-group has-success has-feedback">
			<input type="text" name="loginacct" class="form-control" id="loginacct" placeholder="请输入登录账号" autofocus>
			<span style="font-size:22px" class="glyphicon glyphicon-user form-control-feedback"></span>
		  </div>
		  <div class="form-group has-success has-feedback">
			<input type="password" name="userpswd" class="form-control" id="userpswd" placeholder="请输入登录密码" style="margin-top:10px;">
			<span style="font-size:22px" class="glyphicon glyphicon-lock form-control-feedback"></span>
		  </div>
		  <div class="form-group has-success has-feedback">
			<select id="roleid" name="roleid" class="form-control" >
                <option value="member">会员</option>
                <option value="user">管理</option>
            </select>
		  </div>
        <div class="checkbox">
          <label>
            <input type="checkbox" value="remember-me"> 记住我
          </label>
          <br>
          <label>
              <a href="forget.html">找回密码</a>
          </label>
          <label style="float:right">
            <a href="reg.html">我要注册</a>
          </label>
        </div>
        <a class="btn btn-lg btn-success btn-block" onclick="dologin()" > 登录</a>
       <!--   <input type="submit" class="btn btn-lg btn-success btn-block" value="登录"/>-->
      </form>
    </div>
    <script src="../jquery/jquery-2.1.1.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../jquery/layer/layer.js"></script>
    <script>
    function dologin() {
        var loginacct = $("#loginacct");
        var userpswd = $("#userpswd");
        if(loginacct.val()==""){
            layer.msg("用户名不能为空！",{time:2000,icon:5,shift:6},function () {
                loginacct.focus();
            })
            return;
        }
        if(userpswd.val()==""){
            layer.msg("密码不能为空！",{time:2000,icon:5,shift:6},function () {
                userpswd.focus();
            })
            return;
        }

        var selected = $("#roleid").val();
        if(selected == "user"){
            $.ajax({
                url:"/managers/userlogin.do",
                type:"POST",
                dataType:"json",
                data:{
                    "loginacct":loginacct.val(),
                    "userpswd":userpswd.val()

                },
                beforeSend: function () {
                    loadingIndex = layer.msg('处理中',{icon:16});
                },
                success:function (result) {
                    layer.close(loadingIndex);
                    var UserRole = $("#UserRole");
                    if(result.success){
                        window.location.href = "/managers/main1.html";
                    }else{
                        layer.msg("用户名或密码错误，请重新输入",{time:1000,icon:5,shift:6});
                    }
                },
                error:function () {
                    layer.msg("用户登录失败",{time:1000,icon:5,shift:6});
                }
            });
        }else {
            $.ajax({
                url:"/member/memberlogin.do",
                type:"POST",
                dataType:"json",
                data:{
                    "loginacct":loginacct.val(),
                    "userpswd":userpswd.val()

                },
                beforeSend: function () {
                    loadingIndex = layer.msg('处理中',{icon:16});
                },
                success:function (result) {
                    layer.close(loadingIndex);
                    var UserRole = $("#UserRole");
                    if(result.success){
                        window.location.href = "/index.jsp";
                    }else{
                        layer.msg("用户名或密码错误或者未激活，请重试",{time:1000,icon:5,shift:6});
                    }
                },
                error:function () {
                    layer.msg("用户登录失败",{time:1000,icon:5,shift:6});
                }
            });

        }

    }
    </script>
  </body>
</html>